﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Simple.Repository.Migrations
{
    public partial class _16 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "CreateUserName",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.AlterColumn<string>(
                name: "LeaveMessageContent",
                table: "Class_DynamicLeaveMessage",
                type: "longtext",
                nullable: true,
                comment: "留言内容",
                oldClrType: typeof(string),
                oldType: "longtext",
                oldComment: "留言内容")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "ClassId",
                table: "Class_DynamicLeaveMessage",
                type: "char(36)",
                nullable: true,
                comment: "所在班级id",
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<bool>(
                name: "IsPublish",
                table: "Class_DynamicLeaveMessage",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "是否发布");

            migrationBuilder.AddColumn<bool>(
                name: "IsReply",
                table: "Class_DynamicLeaveMessage",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "是否回复");

            migrationBuilder.AddColumn<DateTime>(
                name: "LeaveMessageTime",
                table: "Class_DynamicLeaveMessage",
                type: "datetime(6)",
                nullable: true,
                comment: "留言时间");

            migrationBuilder.AddColumn<string>(
                name: "LeaveMessageUserId",
                table: "Class_DynamicLeaveMessage",
                type: "longtext",
                nullable: true,
                comment: "留言人id")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "LeaveMessageUserName",
                table: "Class_DynamicLeaveMessage",
                type: "longtext",
                nullable: true,
                comment: "留言人姓名")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Class_LeaveMessageReply",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    ReplyContent = table.Column<string>(type: "longtext", nullable: true, comment: "回复内容")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ReplyUserName = table.Column<string>(type: "longtext", nullable: true, comment: "回复人姓名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ReplyTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "回复人时间"),
                    LeaveMessageId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "留言Id", collation: "ascii_general_ci"),
                    ParentId = table.Column<string>(type: "longtext", nullable: true, comment: "父级回复")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsPublish = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "是否发布"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Class_LeaveMessageReply", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Class_LeaveMessageReply_Class_DynamicLeaveMessage_LeaveMessa~",
                        column: x => x.LeaveMessageId,
                        principalTable: "Class_DynamicLeaveMessage",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Class_LeaveMessageReply_LeaveMessageId",
                table: "Class_LeaveMessageReply",
                column: "LeaveMessageId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Class_LeaveMessageReply");

            migrationBuilder.DropColumn(
                name: "ClassId",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.DropColumn(
                name: "IsPublish",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.DropColumn(
                name: "IsReply",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.DropColumn(
                name: "LeaveMessageTime",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.DropColumn(
                name: "LeaveMessageUserId",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.DropColumn(
                name: "LeaveMessageUserName",
                table: "Class_DynamicLeaveMessage");

            migrationBuilder.UpdateData(
                table: "Class_DynamicLeaveMessage",
                keyColumn: "LeaveMessageContent",
                keyValue: null,
                column: "LeaveMessageContent",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "LeaveMessageContent",
                table: "Class_DynamicLeaveMessage",
                type: "longtext",
                nullable: false,
                comment: "留言内容",
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true,
                oldComment: "留言内容")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "CreateUserName",
                table: "Class_DynamicLeaveMessage",
                type: "longtext",
                nullable: false,
                comment: "留言人姓名")
                .Annotation("MySql:CharSet", "utf8mb4");
        }
    }
}
